package com.xkstream.client.presenter.kt

import com.xkstream.client.api.UserApi
import com.xkstream.client.api.UserService
import com.xkstream.client.base.BaseData
import com.xkstream.client.base.BasePresenterImpl
import com.xkstream.client.base.BaseView
import com.xkstream.client.entity.kt.RewardData
import com.xkstream.client.rx.RxHelper
import com.xkstream.client.rx.RxObserver
import com.xkstream.client.videothumbloader.core.VideoThumbLoader

/**
 * Created by xiaoyi on 2017-11-3.
 */
class RewardPresenter() : BasePresenterImpl(), RewardContract.Presenter {
    var view: RewardContract.View? = null
    var userService: UserService? = null

    constructor(view: RewardContract.View) : this() {
        this.view = view
        this.view?.setPresenter(this)
        this.userService = UserApi.getInstance().service
    }


    override fun getRewardInfo(params: Map<String, Any>) {
        view?.showLoading()
        userService?.getRewardInfo(params)
                ?.compose(RxHelper.toUI())
                ?.subscribe(object : RxObserver<BaseData<RewardData>>(this) {
                    override fun onFail(message: String) {
                        view?.hideLoading()
                        view?.showError(message)
                    }

                    override fun onSuccess(t: BaseData<RewardData>) {
                        view?.hideLoading()
                        view?.showRewardInfo(t)
                    }
                })
    }
}